/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cracking.codeing.in;

/**
 *
 * @author aasharm2
 */
public class spaceString {

    public static final String inputStr = "Mr John Smith    ";
    public static final String compressedStr = "aaabbbccbbbdd";

    public static void main(String[] args) {
        char str[] = inputStr.trim().toCharArray();
        StringBuffer sb = new StringBuffer();
        char buff[] = inputStr.toCharArray();
        int newLength = 0;
        for (int i = 0; i < str.length; i++) {
            if (str[i] == ' ') {
                sb.append('%');
                sb.append('2');
                sb.append('0');
            } else {
                sb.append(str[i]);
            }
        }
        System.out.println(sb.toString());
        char compressedChar [] = getCompressedStr();
        System.out.println(compressedChar);
                
    }

    public static char [] getCompressedStr() {
        String str = "";
        char compChar[] = compressedStr.toCharArray();
        char tempChar[] = new char[compressedStr.length()];
        int charCount = 0;
        int tempcharLen = 0;
        for (int i = 0; i < compressedStr.length()-1; i++) {
            if (compChar[i] == compChar[i + 1]) {
                charCount++;
            } else {
                tempChar[tempcharLen] = compChar[i];
                tempChar[tempcharLen + 1] = (char) charCount;
                tempcharLen += 2;
                charCount = 0 ;
            }
        }

        return tempChar;
    }
}
